package com.jhy.study2;

import java.io.*;
import com.sun.org.apache.bcel.internal.classfile.ConstantString;
import org.gjt.jclasslib.io.ClassFileWriter;
import org.gjt.jclasslib.structures.ClassFile;
import org.gjt.jclasslib.structures.Constant;
import org.gjt.jclasslib.structures.constants.ConstantDoubleInfo;
import org.gjt.jclasslib.structures.constants.ConstantUtf8Info;
import org.gjt.jclasslib.structures.constants.ConstantStringInfo;

public class Testor1 {
    public static void main(String[] args) throws Exception {

//        String filePath = "C:\\Users\\HMS\\Desktop\\AppService.class";
        String filePath = "C:\\Users\\14472\\Desktop\\WfmExcelExportController.class";
        FileInputStream fis = new FileInputStream(filePath);

        DataInput di = new DataInputStream(fis);
        ClassFile cf = new ClassFile();
        cf.read(di);
        Constant[] infos = cf.getConstantPool();

        int count = infos.length;
        for (int i = 0; i < count; i++) {
            if (infos[i] != null) {
                if(i==52){
                    System.out.print(i);
                    System.out.print(" = ");
                    System.out.print(infos[i].getVerbose());
                    System.out.print(" = ");
                    System.out.println(infos[i]);
                    System.out.println(infos[i].getClass().getSimpleName());
                    ConstantUtf8Info uInfo = (ConstantUtf8Info)infos[i];//根据对应的类型转换
                    uInfo.setString("UTF-8");
                    infos[i]=uInfo;
                }
            }
        }
        cf.setConstantPool(infos);
        fis.close();
        //File f = new File(filePath);
        //ClassFileWriter.writeToFile(f, cf);
    }

}
